# Script to invoke EmSenseAPI/Upload
import json, urllib2, random, time, math, threading, datetime

# Generate 100 upload requests/second for sensorIDs [1-10], take 60 readings - each reading being a number betweeen 0 to 1000
# Run this function for 10 minutes
def makeUploadRequest():
	noOfSecondsPassed = 0
	while noOfSecondsPassed < 600:	#10 minutes
		reqCount = 0
		while reqCount < 100:
			
			snrID = random.randrange(1,10)
			timestamp = math.floor(time.time())
			index = 0
			# generating sensor readings
			snrRgs = []
			while index < 60:
				snrRgs.append(random.randrange(0,1000))
				index += 1
			uploadData = {
					"sensorID": snrID,
					"time": timestamp,
					"sensorReadings": snrRgs
			}
			ureq = urllib2.Request('http://localhost:9000/emsense/upload')
			ureq.add_header('Content-Type', 'application/json')
			response = urllib2.urlopen(ureq, json.dumps(uploadData))
			print response.read()
			reqCount+=1
		noOfSecondsPassed +=1
		time.sleep(1.0)

# Call function
makeUploadRequest()
